import request from "@/utils/request"
import type {
  SpuListParams,
  getSpuListApiRosponse,
  BaseSaleAttrList,
  SpuItem,
  SpuSaleAttrList,
  SpuImageList,
} from "./modles/spuModels";



enum Api {
  getSpuList = "/admin/product", //获取列表展示
  getBaseSaleAttrLis = "/admin/product/baseSaleAttrList", //获取销售属性
  saveSpuInfo = "/admin/product/saveSpuInfo", //添加数据的请求
  getSpuSaleAttrList = "/admin/product/spuSaleAttrList", //修改时获取的属性值列表
  getSpuImageList = "/admin/product/spuImageList", //修改时要获取图片
  upSpuInfo = "/admin/product/updateSpuInfo", //修改
  deleteSpu = "/admin/product/deleteSpu", //删除
}

export const getSpuListApi = ({ page, limit, category3Id }: SpuListParams) => {
  return request.get<any, getSpuListApiRosponse>(
    `${Api.getSpuList}/${page}/${limit}`,
    {
      params: {
        category3Id,
      },
    }
  );
};


// 获取基础销售属性列表
export const getBaseSaleAttrListApi = ()=>{
  return request.get<any, BaseSaleAttrList>(Api.getBaseSaleAttrLis);
}


// 添加Spu
export const getSaveSpuInfoApi = (data: SpuItem) => {
  return request.post<any,null>(Api.saveSpuInfo, data);
};


// 获取销售属性列表
export const getSpuSaleAttrListApi =(spuId:number)=>{
  return request.get<any, SpuSaleAttrList>(
    `${Api.getSpuSaleAttrList}/${spuId}`
  );
}

// 获取图片
export const getSpuImageListApi =(id:number)=>{
   return request.get<any, SpuImageList>(`${Api.getSpuImageList}/${id}`);
}

// 修改数据属性，属性名
 export const getUpSpuInfoApi = (data: SpuItem) => {
   return request.post(Api.upSpuInfo,data);
 };

//  删除
 export const deleteSpuApi =(id:number)=>{
   return request.delete<any,null>(`${Api.deleteSpu}/${id}`)
 }  